﻿using Anke.SHManage.BLL;
using Anke.SHManage.MSSQLDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class LS_EntryListModeWebForm : System.Web.UI.Page
    {
        private string reportName;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.EntryListType.Visible = false;
            this.getinLable.Visible = false;
            if (!IsPostBack)
            {
                InitPage();

            }
            else
            { 
                reportName = Convert.ToString(ViewState["reportName"]); 
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();         
        }
        private void InitPage()
        {
            this.StartDate.Text = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
            this.EndDate.Text = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
            reportName = Request.QueryString["ReportName"];
            ViewState["reportName"] = reportName;
            BindReportDataSource();
        }

        protected void BindReportDataSource()
        {

            DateTime start = Convert.ToDateTime(this.StartDate.Text);
            DateTime end = Convert.ToDateTime(this.EndDate.Text);
            string entryStorage = (this.EntryStorage.Text).ToString();
            string entryListType = Convert.ToString(this.EntryListType.Text);
            string entryListCode = Convert.ToString(this.EntryListCode.Text);
            string classification = Convert.ToString(this.Classification.Text);
            string material = (this.Material.Text).ToString();
            string vendor = Convert.ToString(this.Vendor.Text);
            //取登录人的仓库权限（仓库id）
            List<int> StroageIDs = new List<int>();
            StroageIDs = UserOperateContext.Current.Session_StorageRelated.listUserStorage;    
            string instr = "";
            foreach (int item in StroageIDs)
            {
                instr +=  "'"+ item +" ',";
            }
            instr = instr.Substring(0, instr.Length - 1);
            
            string start1 = start.ToString();
            string end1 = end.ToString();


            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/" + reportName);
            //this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/LS_EntryList.rdlc");
            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("StartTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("EndTime", end1);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed });
            LSDAL dal = new LSDAL();
            switch (reportName)
            {
                case "LS_EntryList.rdlc":
                    this.Page.Title = "入库单流水表";
                    this.Vendor.Visible = false;
                    this.supplier.Visible = false;
                    DataTable dt = dal.Get_LS_EntryList(start, end, instr, entryStorage, entryListType, entryListCode);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForLS_EntryList", dt));
                    break;
                case "LS_XEntryList.rdlc":
                    this.Page.Title = "新入库单流水表";
                    Microsoft.Reporting.WebForms.ReportParameter ecode = new Microsoft.Reporting.WebForms.ReportParameter("EntryCode", entryListCode);
                    this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed, ecode });
                    DataTable dt1 = dal.Get_LS_XEntryList(start, end, instr, entryStorage, entryListType, entryListCode, classification, material,vendor);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForLS_XEntryList", dt1));
                    break;
                default:
                    break;
            }
            this.ReportViewer1.LocalReport.Refresh();
            //DataTable dt = dal.Get_LS_EntryList(start, end, instr,entryStorage, entryListType, entryListCode);
            //this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForLS_EntryList", dt));
            //this.ReportViewer1.LocalReport.Refresh();
        }
    }
}